package com.asnike.display{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ASDoc{
		
		static public function get SPRITE():Sprite{
			return new Sprite;
		}
		
		static public function GET( $parent:*, $selector:String ):DisplayObject{
			var i:int, j:int, hierachy:Array, result:*;
			
			hierachy = $selector.split( '.' );
			result = $parent;
			for( i = 0, j = hierachy.length ; i < j ; ++i ){
				result = result.getChildByName( hierachy[i] );
			}
			
			return result;
		}
		
		static public function ADD( $parent:*, $child:DisplayObject, $params:Object ):DisplayObject{
			$parent.addChild( $child );
			SET( $child, $params );
			
			return $child;
		}
		
		static public function SET( $target:*, $parmas:Object ):void{
			if( $target is String ){
//				$target = GET( $target );
			}
			applyParams( $target, $parmas );
		}
		static private function applyParams( $target:DisplayObject, $params:Object ):void{
			var key:*;
			
			addEvents( $target, $params );
			$params = parseParams( $params );
			
			for( key in $params ){
				$target[key] = $params[key];
			}
		}
		static private function addEvents( $target:DisplayObject, $params:Object ):void{
			var key:*, event:Object;
			
			if( $params.event ){
				event = $params.event;
				for( key in event ){
					if( key === 'over' ){
						$target.addEventListener( MouseEvent.MOUSE_OVER, event[key] );
					}else if( key === 'out' ){
						$target.addEventListener( MouseEvent.MOUSE_OUT, event[key] );
					}else if( key === 'click' ){
						$target.addEventListener( MouseEvent.CLICK, event[key] );
					}else if( key === 'down' ){
						$target.addEventListener( MouseEvent.MOUSE_DOWN, event[key] );
					}else if( key === 'up' ){
						$target.addEventListener( MouseEvent.MOUSE_DOWN, event[key] );
					}
				}
				delete $params.event;
			}
		}
		static private function parseParams( $params:Object ):Object{
			var key:*, result:Object;
			
			result = {};
			for( key in $params ){
				if( key === 'a' ){
					result.alpha = $params[key];
				}else if( key === 'w' ){
					result.width = $params[key];
				}else if( key === 'h' ){
					result.height = $params[key];
				}else if( key === 'sx' ){
					result.scaleX = $params[key];
				}else if( key === 'sy' ){
					result.scaleY = $params[key];
				}else if( key === 'scale' ){
					result.scaleX = $params[key];
					result.scaleY = $params[key];
				}else{
					result[key] = $params[key];
				}
			}
			
			for( key in $params ){
				if( key === 'w' || key === 'h' || key === 'sx' || key === 'sy' || key === 'scale' || key === 'a' ){
					delete result[key];
				}
			}
			
			return result;
		}
		
		
		public function ASDoc(){
			
		}
	}
}